package cn.ora.multimodulehilt

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import cn.ora.base.ISkill
import cn.ora.multimodulehilt.databinding.ActivityMainBinding

import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject

@AndroidEntryPoint
class MainActivity : AppCompatActivity() {

    @Inject
    lateinit var skillMap: MutableMap<String, Class<*>>

    lateinit var binding: ActivityMainBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(binding.root)
        binding.btnUser.setOnClickListener {
            action("user")
        }
        binding.btnNews.setOnClickListener {
            action("news")
        }
        binding.btnApp.setOnClickListener {
            action("app")
        }
        var ret = "All skills:\n"
        skillMap.forEach {
            ret += it.key + " : " + it.value + "\n"
        }
        binding.text.text = ret
    }

    fun action(skillName: String) {
        val skillClz = skillMap[skillName]
        if (skillClz != null) {
            val obj = skillClz.newInstance()
            if (obj is ISkill) {
                binding.ret.text = obj.action()
            }
        }
    }
}